/**
 * @(#)MyClient.java 2009-11-10 Copyright 2009 LINKAGE, Inc. All rights reserved. LINKAGE PROPRIETARY/CONFIDtheENTIAL.
 *                   Use is subject to license terms.
 */
package com.xzssmk.leisure.x.util;

import java.io.InputStream;
import java.io.OutputStream;

import com.linkage.netmsg.NetMsgclient;
import com.linkage.netmsg.server.ReceiveDemo;
import com.linkage.netmsg.server.ReceiveMsg;

/**
 * @description
 * @author li
 * @date 2009-11-10
 * @version 1.0.0
 * @since 1.0
 */
public class SMSUtil {

    static OutputStream out;

    static InputStream in = null;

    public static boolean result;

    /**
     * @description
     * @author li
     * @date 2009-11-10
     * @version 1.0.0
     * @param args
     */

    public static void main(String[] args) {

        SMSUtil.sendMsg("15150049049", "123456");

    }

    public static boolean sendMsg(String phone, String code) {
        NetMsgclient client = new NetMsgclient();

        /*ReceiveMsgImpl为ReceiveMsg类的子类，构造时，构造自己继承的子类就行*/
        ReceiveMsg receiveMsg = new ReceiveDemo();

        client = client.initParameters("58.218.206.155", 9005, "0516990001", "377236421", receiveMsg);

        try {

            /*登录认证*/
            boolean isLogin = client.anthenMsg(client);
            if (!isLogin) {
                System.out.println("sms login failure");
                return isLogin;
            }

            /*发送下行短信*/
            client.sendMsg(client, 0, phone,
                "尊敬的客户\n" + "徐州市民卡惠民卡系统\n" + "诚邀您入驻,邀请码为" + code + "\n" + "请关注“徐州市民卡”微信公众服务平台（xzsmk002）", 1);

            // 关闭发送短信与接收短信连接
            client.closeConn();
            return isLogin;
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return false;
    }

}
